package com.woorigil.social.controller;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.servlet.view.RedirectView;

import com.woorigil.social.Context;
import com.woorigil.social.MenuCategory;

public class BaseController {
	public String getForwordPage(String viewName) {
		return viewName + Context.get().getLayout();
	}
	
	public RedirectView getRedirectUrl(String url) {
		String extention = Context.get().getExtention();
		if (StringUtils.isNotBlank(extention)) {
			url = url + "." + extention;
		}
		return new RedirectView(url);
	}
	
	public String getUserAgent() {
		return Context.get().getUserAgent();
	}
	
	public String getRemoteAddr() {
		return Context.get().getRemoteAddr();
	}
	
	public List<Integer> getSubCategoryIds() {
		if (Context.get().getSubMenuId() != 0) {
			return Arrays.asList(Context.get().getSubMenuId());
		} else if (Context.get().getMainMenuId() != 0) {
			MenuCategory mainMenu = Context.getMainCategory(Context.get().getMainMenuId());
			return mainMenu.getSubCategoryIds();
		}
		return null;
	}
}
